package com.shanjupay.merchant.controller;

import com.shanjupay.merchant.api.AppService;
import com.shanjupay.merchant.api.dto.AppDTO;
import com.shanjupay.merchant.common.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author whb
 * @create 2021-12-04 15:18
 * @desciption app应用controller控制类
 */
@Api(value = "商户平台-应用管理",tags = "商户平台-应用相关",description = "商户平台-应用管理")
@RestController
public class AppController {
    @Reference
    AppService appService;

    /**
     * 创建app应用
     * @param appDTO
     * @return
     */
    @ApiOperation("商户创建app应用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appDTO",value = "App应用信息",dataType = "AppDTO",required = true,paramType = "body")
    })
    @RequestMapping(value = "/my/apps",method = RequestMethod.POST)
    public AppDTO createApp(@RequestBody AppDTO appDTO){
        Long merchantId = SecurityUtil.getMerchantId();//从token获取商户id
        return appService.createApp(merchantId, appDTO);
    }

    /**
     * 查询商户下应用列表
     * @return 返回应用列表
     */
    @ApiOperation("商户下应用列表")
    @RequestMapping(value = "/my/apps",method = RequestMethod.GET)
    public List<AppDTO> queryAppListByMerchantId(){
        Long merchantId = SecurityUtil.getMerchantId();//从token获取商户id
        return appService.queryAppByMerchantId(merchantId);
    }

    /**
     * 根据应用id查询应用信息
     * @param appId 应用id
     * @return 应用dto对象
     */
    @ApiOperation("根据应用id查询应用信息")
    @ApiImplicitParam(name = "appId",value = "应用id",dataType = "String",required = true,paramType = "path")
    @RequestMapping(value = "/app/app/{appId}",method = RequestMethod.GET)
    public AppDTO queryAppById(@PathVariable("appId") String appId){
        return appService.queryAppById(appId);
    }
}
